package com.damai.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.citywithincity.db.Db;


public class RawAction  implements IAction {
	
	
	private String key;
	
	private Method method;
	
	private Object controller;
	
	public RawAction(String key,Method method,Object controller){
		this.key = key;
		this.method = method;
		this.controller = controller;
	}

	@Override
	public void doFilter(HttpServletRequest request, HttpServletResponse response) throws IOException {
		try {
			method.invoke(controller, request,response);
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		} catch (InvocationTargetException e) {
			throw new RuntimeException(e);
		}finally{
			Db.release();
		}
	}

	@Override
	public String getKey() {
		return key;
	}

	

}
